define([ "jquery","site_tip","jquery.ajax.ext"],  function( $,Site_tip ) {
	$.ajaxSetup ({
		 cache: false, //关闭AJAX相应的缓存
		 error: function(e){
			 if((e.status>=400 && e.status<=599))
			 {
				 var tip = new Site_tip();
				 //tip.isAnimal=true;
				 tip.setContent("服务器请求超时，请稍后重试!",true,false);
				 tip.show();
				 $("body").trigger("networkError");
			 }
			 //console.log(Site_tip);
			// alert("网络连接失败！");
			 /*Site_tip.setContent("网络连接失败!");
			 Site_tip.show();*/

		 },
		 complete:function()
		 {
			 $("body").trigger("ajaxComplete");
		 }
	});
	/*//修改ajax
	var _ajax=$.ajax;
	//重写jquery的ajax方法
	$.ajax=function(opt){
		//备份opt中success方法
		var fn = {
			success:function(data, textStatus){}
		}
		if(opt.success){
			fn.success=opt.success;
		}

		//扩展增强处理
		var _opt = $.extend(opt,{
			success:function(data, textStatus){
				//成功回调方法增强处理
				try{
					if(data.error_code==1011){
						window.location.href = "/login";
						return false;
					}
				} catch(e){

				}
				fn.success(data, textStatus);
			}
		});
		return _ajax(_opt);
	};*/


	/*requirejs.onError = function (err) {
		console.log(err.requireType);
		if (err.requireType === 'timeout') {
			console.log('modules: ' + err.requireModules);
		}

		throw err;
	};*/
	return {
		get_file_type : function(filetype) {
			var arr = filetype.toLowerCase().split(".");
			if (!arr) {
				return "文件名称没有后缀名";
			}
			var len = arr.length;
			return arr[len - 1];
		},
		getSiteRoot : function(isVirtual) {
			var siteRoot = window.location.protocol + "//"
					+ window.location.host + "/";
			if (!isVirtual)
				return siteRoot;

			var relativePath = window.location.pathname;
			if (relativePath != "" && relativePath.substring(0, 1) == "/") {
				// 此处重要，不同的浏览器可能返回的relativePath不一样
				relativePath = relativePath.substring(1);
			}
			var virtualPath = (relativePath == "") ? "" : relativePath
					.substring(0, relativePath.indexOf("/") + 1);

			return siteRoot + virtualPath;
		},
		stopEvent : function(e) {
			try{
				if(e.stopPropagation){
					e.stopPropagation();
				}
			}catch(ex){
				
			}
			
			if (window.event) {
				window.event.cancelBubble = true;
			}
		},
		isIE : function(){
			var flag = /msie/i.test(navigator.userAgent) && !window.opera;
			return flag;
		},
		lessThenIE : function(value){
			var UA = navigator.userAgent, isIE = UA.indexOf('MSIE') > -1, v = isIE ? /\d+/
					.exec(UA.split(';')[1])
					: 'no ie';
			var tt = v[0] < value;
			return v[0] < value;
		},
		highlight : function (str,key,element) {
			var index = str.toLowerCase().indexOf(key.toLowerCase()); 
			if(index>2){
				var keystr = str.substr(index ,key.length);
				var specil = ".&"
				if(specil.indexOf(key) != -1){
					if(key == "&"){
						key = "&amp;";
					}else{
						key = "\\"+key;
					}
					
				}
				
				var re=new RegExp(key,'gi');//创建含变量的正则表达式   
				var newstr="<span style='color:#d33b3b'>" + keystr + "</span>";//将关键字替换成newstr的形式
				var targetstr= str.replace(re,newstr);//执行替换 
				element.html(targetstr);
			}
		},
		loadCss: function (url) {
			var find = $("head link[href='"+url+"']");
			if(find.length>0)
			{
				return;
			}
		    var link = document.createElement("link");
		    link.type = "text/css";
		    link.rel = "stylesheet";
		    link.href = url;
		    document.getElementsByTagName("head")[0].appendChild(link);
		},
		getQueryString: function (name) {
		    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		    var r = window.location.search.substr(1).match(reg);
		    if (r != null) return unescape(r[2]); return null;
		},
		getHashString:function(name){
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.hash.substr(1).match(reg);
			if (r != null) return unescape(r[2]); return null;
		}
		,
		formatDate:function (d) {
			var now = new Date(d);
			var year = now.getFullYear();
			var clock = year + "-";
			var month = now.getMonth() + 1;
			var day = now.getDate();
			var hh = now.getHours();
			var mm = now.getMinutes();
			var ss = now.getSeconds();

			if (month < 10)
				clock += "0";

			clock += month + "-";

			if (day < 10)
				clock += "0";

			clock += day + " ";
			if (hh < 10)
				clock += "0";
			clock += hh + ":";
			if (mm < 10)
				clock += "0";
			clock += mm;
			return (clock);
		},
		NewGuid:function(){
			var S4 = function() {
				return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
			}
			return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4()
					+ S4() + S4());
		},
		checkSpecialStr:function(str){
			if(str.indexOf("\\") != -1){
				return false;
			}
			var txt = new RegExp("[\*,\\,\/,\?,\",\<,\>,\|,\:]",'gi');
			if (txt.test(str)) { 
				return false;
			}
			return true;
		},
		copyToClipboard:function (text)
		{
		     if (window.clipboardData) // IE
		     {
		         window.clipboardData.setData( "Text" , text);
		         return true;
		     }
		     return false;
		},
		getChkboxs:function(list){
			var selChkboxs = list.find(".icon-checkbox.hover:visible");
			return selChkboxs;
		},
		getSelFiles:function(type){
			var list;
			if(type == undefined){
				list = $("#mypage").find(".wfc");
			}else if(type == 0){
				list = $("#mypage").find(".wfc[data-type='file']");
			}else if(type == 1){
				list = $("#mypage").find(".wfc[data-type='folder']");
			}
			
			return list;
		},
		getHashUrl:function(key)
		{
			var hash = location.hash.replace("#","");
			if(!hash)
			{
				return "";
			}
			var hash_arr = hash.split("&");
			var url = {};
			$.each(hash_arr,function(k,v){
				var tmp = v.split("=");
				url[tmp[0]]=tmp[1]||"";
			});
			return url[key]?url[key]:"";
		},
		bindDisableHandler : function(btns)
		{
			if(btns)
			{
				$.each(btns,function(){
					var btn = $(this);
					btn.attr("disabled",true);
					$("body").one("networkError",function(){
						if(typeof(btn)!="undefined")
						{
							btn.attr("disabled",null);
						}
					});
				});
			}
		},
		enableBtn:function(btns)
		{
			if(btns)
			{
				$.each(btns,function(){
					var btn = $(this);
					btn.attr("disabled",null);
				});
			}
		},
		ajaxErrorCommon:function(e){
			if((e.status>=400 && e.status<=599))
			{
				var tip = new Site_tip();
				//tip.isAnimal=true;
				tip.setContent("服务器请求超时，请稍后重试!",true,false);
				tip.show();
				$("body").trigger("networkError");
			}
		}
	}
});